//path:js/slide-category.js
define(function(require){
	var $=require("jq");
	/**
	 * vip专区不展示分类下拉
	 */
	var isVip = $("#headerConfig").attr("data-isVip")=="yes"?true:false;
	if(isVip){
		return ;
	}
	function SlideCategory(obj){
		var _this_=this;
		//保存对象和对象角色
		this.categoryNode=$(obj);
		this.role=this.categoryNode.attr("data-role");
		//保存一级分类列表
		this.menuItems=$(".menu-item",obj);
		//绑定菜单事件
		this.menuItems.hover(function(){
			var $this=this;
			window.clearTimeout(this.timer2);
			this.timer1=window.setTimeout(function(){
				_this_.showSubMenu($this);
			},100);
		},function(){
			var $this=this;
			window.clearTimeout(this.timer1);
			this.timer2=window.setTimeout(function(){
				_this_.hideSubMenu($this);
			},100);
		});
		//如果不是首页
		if(this.role!="home"){
			//保存一级分类内容区
			this.menuItemsBox=$(".nav-category-menu",obj);
			this.categoryNode.mouseover(function(){
				window.clearTimeout(this.timer3);
				this.timer4=window.setTimeout(function(){
						_this_.menuItemsBox.addClass("nav-category-menu-show");	
				},200);
			}).mouseout(function(){
				window.clearTimeout(this.timer4);
				this.timer3=window.setTimeout(function(){
					_this_.menuItemsBox.removeClass("nav-category-menu-show");	
				},100);
			});
		};
	};
	SlideCategory.prototype={
		//显示子菜单
		showSubMenu:function(thisObj){
			$(thisObj).addClass("selected");
			$(".category-sub",thisObj).addClass("category-sub-show");
			var v=$(thisObj).attr("data-id");
			var v2=$(thisObj).attr("data-order");
			//加载子类(当子类没有被加载)
			if(!$(thisObj).data("isSubLoaded")){
				$(".category-sub",thisObj).html("<p class='loading'><img src='/pinzhiV2.0/images/loading.gif' width='15' height='15' >加载中...</p>").load("/categoryChildren.do?categoryId="+v+"&orderId="+v2,function(){
					//数据加载完成设置完成状态
					$(thisObj).data("isSubLoaded",true);
				});
			};
		},
		//隐藏子菜单
		hideSubMenu:function(thisObj){
			$(thisObj).removeClass("selected");
			$(".category-sub",thisObj).removeClass("category-sub-show");
		}
	};
	
	new SlideCategory($("#J_SlideCategory"));
});

